package com.taoyibao.hongcanting.dialog;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.ui.mine.activity.SetPayPwdStepOneActivity;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.widget.PasswordInputView;

/**
 * @author TangAnna
 * @description: 输入支付密码弹窗
 * @date :${DATA} 14:46
 */
@SuppressLint("ValidFragment")
public class DialogInoutPayPwd extends BaseFragmentDialog implements View.OnClickListener, PasswordInputView.OnFinishListener {


    private TextView mTvPayAmount;
    private TextView mTvBalance;
    private ImageView mIvClose;
    private TextView mTvForget;
    private PasswordInputView mPasswordInputView;
    /**
     * 需要支付的金额
     */
    private double mPayAmount;
    /**
     * 余额
     */
    private double mBalance;

    public DialogInoutPayPwd() {

    }

    public DialogInoutPayPwd(double payAmount, double balance, OnInputFinishListener onInputFinishListener) {
        mPayAmount = payAmount;
        mBalance = balance;
        mOnInputFinishListener = onInputFinishListener;
    }

    @Override
    public void initView(View view) {
        mTvPayAmount = view.findViewById(R.id.tv_dialog_inputPayPwd_payAmount);
        mTvBalance = view.findViewById(R.id.tv_dialog_inputPayPwd_balance);
        mIvClose = view.findViewById(R.id.iv_dialog_inputPayPwd_close);
        mTvForget = view.findViewById(R.id.tv_dialog_inputPayPwd_forget);
        mPasswordInputView = view.findViewById(R.id.piv_dialog_inputPayPwd_input);
    }

    @Override
    public void setListener(View view) {
        super.setListener(view);
        mIvClose.setOnClickListener(this);
        mTvForget.setOnClickListener(this);
        mPasswordInputView.setOnFinishListener(this);
    }

    @Override
    public void setData() {
        super.setData();
        mTvBalance.setText(CodeUtils.formatAmountUnit(mBalance));
        mTvPayAmount.setText(CodeUtils.formatAmountUnit(mPayAmount));

    }

    @Override
    public int bindView() {
        return R.layout.dialog_inout_pay_pwd;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_dialog_inputPayPwd_close://关闭
                dismiss();
                break;
            case R.id.tv_dialog_inputPayPwd_forget://忘记支付密码
                dismiss();
                SetPayPwdStepOneActivity.open(getContext(), CodeUtils.getIdString(R.string.string_ResetPayPwd));
                break;
        }
    }

    private OnInputFinishListener mOnInputFinishListener;

    @Override
    public void setOnPasswordFinished() {
        if (!TextUtils.isEmpty(mPasswordInputView.getOriginText()) && mPasswordInputView.getOriginText().length() == 6) {
            if (mOnInputFinishListener != null) {
                mOnInputFinishListener.onFinish(mPasswordInputView.getOriginText());
            }
            dismiss();
        }

    }

    public interface OnInputFinishListener {
        void onFinish(String result);
    }
}
